import boto3
import json

# [profile Qa]
# aws_access_key_id = "AKIASWZL2UIXMPQQ4NFT"
# aws_secret_access_key = "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"
#
# [profile Prod]
aws_access_key_id = "AKIAVGNWUKMQCF2NKKNR"
aws_secret_access_key = "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"

# aws 认证配置
aws_region = 'us-east-2'
session = boto3.Session(
    aws_access_key_id=aws_access_key_id,
    aws_secret_access_key=aws_secret_access_key,
    region_name=aws_region
)


def load_parameters_from_json(file_path):
    with open(file_path, 'r') as file:
        parameters = json.load(file)
    return parameters


def write_parameters_to_parameter_stores(parameters):
    ssm = session.client('ssm')
    for name, value in parameters.items():
        ssm.put_parameter(
            Name=name,
            Value=value,
            Type='String',  # 可能需要根据情况调整
            Overwrite=True  # 如果存在同名参数则覆盖
        )


if __name__ == "__main__":
    json_file_path = './parameters.json'
    parameters = load_parameters_from_json(json_file_path)
    write_parameters_to_parameter_stores(parameters)
    print("执行完成！")
